<?php
/**
 * Interface for an students to select courses
 */
?>
<html>
<head>

</head>
<body>
<?php
require_once '../dbms_university_courses_mvc/Connection.php';
require_once '../dbms_university_courses_mvc/Model/model_require_once.php';

/* @var $student Student */

$students = Student::getStudents_by_profile_id( $_SESSION ['profile_id'] );
$student = $students [0];

?>
<h1>Previous Courses</h1>
<?php
//get all the courses that the student has taken
$studentCourseRegistrations = StudentCourseRegistration::getStudentCourseRegistrations_by_student_id($student->get_student_id());
?>
<table>
	<tr>
		<th>Name</th>
		<th>Department</th>
		<th>Term</th>
		<th>Credits</th>
		<th>Grade</th>
	</tr>
<?php
/* @var $studentCourseRegistration StudentCourseRegistration */
foreach ( $studentCourseRegistrations as $studentCourseRegistration ) {
	/* @var $course Course */
	$course = Course::constructFrom_course_id($studentCourseRegistration->get_course_id());
	/* @var $term Term */
	$term = Term::constructFrom_term_id($course->get_term_id());
	if ($term->get_year() < 2009) {
		?>
	<tr>
		<td><?php
		echo $course->get_course_name ();
		?></td>
		<td><?php
		/* @var $department Department */
		$department_id = $course->get_department_id ();
		if (isset ( $department_id )) {
			$department = Department::constructFrom_department_id ( $department_id );
			echo $department->get_department_name ();
		}
		?></td>
		<td><?php
		/* @var $term Term */
		$term_id = $course->get_term_id ();
		if (isset ( $term_id )) {
			$term = Term::constructFrom_term_id ( $term_id );
			echo $term->get_term () . " " . $term->get_year ();
		}
		?></td>
		<td><?php
		echo $course->get_credits ();
		?></td>
				<td><?php
		echo $studentCourseRegistration->get_grade();
		?></td>
	</tr>
	
	<?php
	}
}

?>
</table>

</body>
</html>
<?php 
/**
 * Tells you if the department is in the list of the instructor departments
 *
 * @param int $department_id
 * @param array $instructorDepartments
 * @return boolean
 */
function instructorInDepartment($department_id, $instructorDepartments) {
	/* @var $instructorDepartment InstructorDepartment */
	foreach($instructorDepartments as $instructorDepartment){
		if($department_id == $instructorDepartment->get_department_id()){
			return true;
		}
	}
	return false;
}

?>